﻿
namespace Test30.Engine
{
    public class Tile : IDungeonTile
    {
        public TileType Type { get; set; }
        public bool Dirty { get; set; }
        public bool IsSelfLit { get; private set; }
        public bool IsVisible { get; private set; }
        public bool IsExplored { get; private set; }
        public bool IsLitByThing { get; private set; }
        public bool IsLit => IsLitByThing || IsSelfLit;
        public bool IsPassable => Type.IsPassable();
        public bool IsTransparent => Type.IsTransparent();
        public Tile(TileType type, bool isSelfLit)
        {
            Type = type;
            IsSelfLit = isSelfLit;
        }

        public Tile(TileType type)
            : this(type, false)
        {
        }

        public void Light()
        {
            IsSelfLit = true;
        }

        public void LightKnown()
        {
            IsSelfLit = true;
            IsExplored = true;
        }

        #region IDungeonTile Members

        bool IDungeonTile.SetTileType(TileType type)
        {
            if (Type != type)
            {
                Type = type;

                // type changed
                return true;
            }
            else
            {
                // no change
                return false;
            }
        }

        bool IDungeonTile.SetIsVisible(bool isVisible)
        {
            if (IsVisible != isVisible)
            {
                IsVisible = isVisible;

                // visibility changed
                return true;
            }
            else
            {
                // no change
                return false;
            }
        }

        bool IDungeonTile.SetExplored()
        {
            if (!IsExplored)
            {
                IsExplored = true;

                // changed
                return true;
            }
            else
            {
                // no change
                return false;
            }
        }

        bool IDungeonTile.SetTileThingLit(bool isLit)
        {
            if (IsLitByThing != isLit)
            {
                IsLitByThing = isLit;

                // lighting changed
                return true;
            }
            else
            {
                // no change
                return false;
            }
        }

        bool IDungeonTile.SetTilePermanentLit(bool isLit)
        {
            if (IsSelfLit != isLit)
            {
                IsSelfLit = isLit;

                // lighting changed
                return true;
            }
            else
            {
                // no change
                return false;
            }
        }

        #endregion
    }

    
}
